<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<?php
// check if the user is logged-in
include_once '../utils/includer.php';
includeFile('administrator/authentication.php');
isAuthorized();

if (!empty($_POST['isToInsert'])) {
    includeFile("protected/controllers/LinkController.php");
    $linkController = new LinkController();
    $response =  $linkController->createLink($_GET['idc'], $_POST['title'], $_POST['url']);
}

if (!isset($_POST['title']))
    $title = "";
else
    $title = $_POST['title'];

if (!isset($_POST['url']))
    $url = "";
else
    $url = $_POST['url'];

?>

<html>
    <head>        
        <title>WebDoc - Create link</title>

        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" href="../styles/main.css">
        <link rel="stylesheet" type="text/css" href="../styles/admin.css">
        
    </head>
    <body><div id="page" class="rounded">
            <div id="header">
                <div id="logo">Webdoc</div>
            </div>
            <div id="commandbar">
                <div id="menubar">
                    <ul>
                        <li><a href="index.php?idc=<?php echo $_GET['idc']; ?>" title="Back">
                                <img src="../images/back_arrow.png"/></a></li>
                        <li><a href="index.php?idc=1" title="Home">
                                <img src="../images/home.png"/></a></li>
                    </ul>
                </div>
                <div id="topbar">
                    <a href="../protected/ActionDispatcher.php?action=logout">Esci</a>
                </div>
                <hr/>
            </div>
            <div class="contents">
                <div class="pag_tit">Nuovo link</div>                
                <form id="newElementForm" name="newElementForm" method="post" action="createlink.php?idc=<?php echo $_GET['idc'] ?>">
                    <table border="0" cellpadding="1" cellspacing="1" class="box">
                        <tr>
                            <td valign="top" colspan="2">
                                <label>Nome link</label>
                                <input type="text" name="title" size="50" maxlength="255" value="<?php echo $title ?>">
                                <input type="hidden" name="isToInsert" value="true">
                            </td>
                        </tr>
                        <tr>
                            <td valign="top">
                                <label>URL</label>
                                <input type="text" id="url" name="url" size="50" maxlength="255" value="http://">
                            </td>
                            <td valign="top" rowspan="2">
                                <div id="errorbox">
                                <?php 
                                if(isset($response) && $response['status'] == "FAILURE")
                                    echo $response['message'];
                                ?>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td align="right">
                                <br>
                                <input type="submit" value="Salva" />
                            </td>
                        </tr>
                    </table>
                </form>
            </div>
        </div>
    </body>
</html>

